package com.hclc.yxb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hclc.config.aop.log.OperationLogAnnotation;
import com.hclc.entity.model.contans.ApiConst;
import com.hclc.entity.model.page.PageUtil;
import com.hclc.entity.model.result.ResultEntity;
import com.hclc.yxb.ao.AddRoleAndMenuAo;
import com.hclc.yxb.ao.ModRoleAndMenuAo;
import com.hclc.yxb.ao.ModSystemRoleMenuAo;
import com.hclc.yxb.dto.RoleAndMenuDto;
import com.hclc.yxb.dto.RoleAndMenuListDto;
import com.hclc.yxb.dto.SystemMenuDto;
import com.hclc.yxb.model.SysRoleModel;
import com.hclc.yxb.service.RoleManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @ClassName PwlAdministratorManagement
 * @Author: yurj
 * @Mail：1638234804@qq.com
 * @Date: Create in 19:49 2020/8/22
 * @version: 1.0
 */
@Api(tags = "WEB-1.0-RoleManagement", description = "权限管理-权限管理")
@RestController
@RequestMapping("console/role")
@Validated
public class RoleManagementController {

    @Autowired
    private RoleManagementService roleManagementService;

    /**
     * 获取权限和菜单列表
     *
     * @param util
     * @return com.hclc.pwl.model.result.ResultEntity<com.baomidou.mybatisplus.core.metadata.IPage < com.hclc.pwl.dto.AdministratorDvo>>
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/22 21:06
     */
    @ApiOperation("获取权限和菜单列表")
    @PostMapping(value = "/getRoleAndMenu", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity<IPage<RoleAndMenuDto>> getRoleAndMenu(@ApiParam(value = "分页信息") @RequestBody PageUtil util) {
        Page<SysRoleModel> page = new Page<>(util.getCurrent(), ApiConst.PAGE_SIZE);
        return ResultEntity.ResultSuccess(roleManagementService.selectRoleAndMenu(page));
    }

    /**
     * 获取角色下拉
     * @param
     * @return com.hclc.hxwy.model.result.ResultEntity<java.util.List<com.hclc.hxwy.console.dto.RoleAndMenuListDto>>
     * @author ljj
     * @version 1.0
     * @date 2020/10/30 11:25
     */
    @ApiOperation("获取角色下拉")
    @GetMapping(value = "/getRoleAndMenuList", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity<List<RoleAndMenuListDto>> getRoleAndMenuList() {
        return ResultEntity.ResultSuccess(roleManagementService.selectRoleAndMenuList());
    }

    /**
     * 添加角色
     *
     * @param ao
     * @return com.hclc.pwl.model.result.ResultEntity
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/23 10:58
     */
    @OperationLogAnnotation(remark = "添加角色")
    @ApiOperation("添加角色")
    @PostMapping(value = "/addSystemRole", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity addSystemRole(@ApiParam(value = "添加角色和权限") @Validated @RequestBody AddRoleAndMenuAo ao) {
        return ResultEntity.ResultSuccess(roleManagementService.insertSystemRole(ao));
    }

    /**
     * 删除角色和权限
     *
     * @param roleId
     * @return com.hclc.pwl.model.result.ResultEntity
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/23 11:12
     */
    @OperationLogAnnotation(remark = "删除角色")
    @ApiOperation("删除角色")
    @GetMapping(value = "/delSystemRole", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity delSystemRole(@ApiParam(value = "角色id") @NotBlank(message = "角色id不能为空") @RequestParam String roleId) {
        return ResultEntity.ResultSuccess(roleManagementService.deleteSystemRole(roleId));
    }

    /**
     * 修改角色和权限
     *
     * @param ao
     * @return com.hclc.pwl.model.result.ResultEntity
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/23 11:17
     */
    @OperationLogAnnotation(remark = "修改角色")
    @ApiOperation("修改角色")
    @PostMapping(value = "/modSystemRole", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity modSystemRole(@ApiParam(value = "角色信息") @Validated @RequestBody ModRoleAndMenuAo ao) {
        return ResultEntity.ResultSuccess(roleManagementService.updateSystemRole(ao));
    }

    /**
     * 修改角色菜单列表
     * @param ao
     * @return com.hclc.pwl.model.result.ResultEntity
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/23 14:55
     */
    @OperationLogAnnotation(remark = "修改角色菜单列表")
    @ApiOperation("修改角色菜单列表")
    @PostMapping(value = "/modSystemRoleMenu", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity modSystemRoleMenu(@ApiParam(value = "权限列表信息") @Validated @RequestBody ModSystemRoleMenuAo ao) {
        return ResultEntity.ResultSuccess(roleManagementService.updateSystemRoleMenu(ao));
    }

    /**
     * 查询菜单列表
     *
     * @param
     * @return com.hclc.pwl.model.result.ResultEntity<java.util.List < com.hclc.pwl.dto.SystemMenuDto>>
     * @author yurj
     * @mail 1638234804@qq.com
     * @version 1.0
     * @date 2020/8/23 13:18
     */
    @ApiOperation("查询菜单列表")
    @PostMapping(value = "/getSystemMenuList", produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResultEntity<List<SystemMenuDto>> getSystemMenuList() {
        return ResultEntity.ResultSuccess(roleManagementService.selectSystemMenuList());
    }


}
